package com.ccbooks.view;

import com.ccbooks.bo.BookMarkBo;
import com.ccbooks.bo.BooksBo;
import com.ccbooks.bo.FileBo;
import com.ccbooks.listener.BookpagebgClick;
import com.ccbooks.listener.BtnBookMarkOnClickListener;
import com.ccbooks.listener.BtnBookStoreClick;
import com.ccbooks.listener.BtnCatalogueClick;
import com.ccbooks.listener.BtnColorBlackClick;
import com.ccbooks.listener.BtnColorBrownClick;
import com.ccbooks.listener.BtnContentCatelogClick;
import com.ccbooks.listener.BtnContentMarkClick;
import com.ccbooks.listener.BtnFontClick;
import com.ccbooks.listener.BtnFontEnterButtonAClick;
import com.ccbooks.listener.BtnFontEnterButtonClick;
import com.ccbooks.listener.BtnLightClick;
import com.ccbooks.listener.MainContentOnTouchListener;
import com.ccbooks.listener.SbrMainContentOnChangeListener;
import com.ccbooks.util.BooksEngine;
import com.ccbooks.util.ContentDisp;
import com.ccbooks.util.ContentUtil;
import com.ccbooks.util.ContentUtilBookMark;
import com.ccbooks.util.ContentUtilContentSize;
import com.ccbooks.util.ContentUtilFirst;
import com.ccbooks.util.ContentUtilReturn;
import com.ccbooks.util.CursorController;
import com.ccbooks.util.StringConfig;
import com.ccbooks.util.TextSizeUtil;
import com.ccbooks.util.PDB.BooksEnginePDB;
import com.ccbooks.util.PDB.ContentDispPDB;
import com.ccbooks.util.PDB.ContentUtilBookMarkPDB;
import com.ccbooks.util.PDB.ContentUtilFirstPDB;
import com.ccbooks.util.PDB.ContentUtilPDB;
import com.ccbooks.util.PDB.ContentUtilReturnPDB;

import com.ccbooks.vo.Book;
import com.ccbooks.vo.CatelogItem;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.inputmethodservice.Keyboard.Key;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class BookContentView extends Activity {

	// 所有控件；
	private Button btnBookStore;
	private Button btnCatalogue;
	private Button btnLight;
	private Button btnFont;
	private Button btnSearch;
	public Button btnBookMark;
	private LinearLayout bookpagebg; // 竖屏书背景；

	private TextView tvBookNameContent;
	// private LinearLayout llyContentMain;
	private LinearLayout llyContentMain;
	public TextView tvMainContent;
	public SeekBar sbrMainContent;
	private LinearLayout llyCatelogTitle;
	public TextView tvMainContentLeft;
	public TextView tvMainContentRight;

	private LinearLayout btnLightEnter; // 亮度调节悬浮框；
	private LinearLayout btnFontEnter; // 字体调节悬浮框；
	private Button btnFontEnterButtona1; // 字体变小按钮；
	private Button btnFontEnterButtonA2; // 字体变大按钮；
	private Button btnFontEnterColorBlack; // 白背景按钮；
	private Button btnFontEnterColorBrown; // 棕色背景按钮；

	private SeekBar btnLightBar; // 屏幕亮度控制拖动条；
	
	public short showCatelogType; // 目录显示规则 1表示目录，2表示书签；
	public short showLightEnter = 1; // 亮度调节悬浮框打开状态，1表示未打开，2表示已经打开，3表示无效；
	public short showFontEnter = 1; // 字体调节悬浮框打开状态，1表示未打开，2表示已经打开，3表示无效；
	public short portraint; // 横竖屏显示 横屏为2，竖屏为1；
	public short showFontEnterButtona1 = 1; // 字体变小按钮选中状态，1表示未选中，2表示已选中；
	public short showFontEnterButtonA2 = 1; // 字体变大按钮选中状态，1表示未选中，2表示已选中；
	public short showColorBlack = 1; // 白背景颜色选择状态，1表示未选中，2表示已选中；
	public short showColorBrown = 1; // 棕色背景颜色选择状态，1表示未选中，2表示已选中；
	private float ness ; //屏幕亮度当前值
	
	/**获得书ID*/
	private int id;
	/**获得书类*/
	public Book book;
	public ContentUtil cu; // 分页类
	public ContentDisp cd;
	public ContentUtilFirst cuf;
	public ContentUtilPDB cuPDB; // 分页类
	public ContentDispPDB cdPDB;
	public ContentUtilFirstPDB cufPDB;
	public ContentUtilReturnPDB curPDB;

	public int lineIndex; // 开头行号
	public int lineCount;	//	总行数；
	public int isMark;	//是否书签,并显示书签的值；
	public ContentUtilReturn cur;
	public CursorController cc;
	public ContentUtilContentSize cucs;
	public CatelogItem mark;
	
	public boolean turnable;
	/**对话框提示*/
	public Dialog dg;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Bundle bundle = this.getIntent().getExtras();
		id = bundle.getInt("bookId");
		BooksBo bo = new BooksBo(this, false);
		book = bo.getOne(id);
		if (this.getResources()
				.getConfiguration()
				.orientation == 
				Configuration.ORIENTATION_PORTRAIT) { // ����
			// 竖屏
			portraint = 1;
			setContentView(R.layout.book_page);

		} else {
			// 横屏
			portraint = 2;
			setContentView(R.layout.book_page_horizontal);
		}
		findview();
		addListener();
		
		doing(portraint);
		
		
	}

	/**切换屏幕时候的显示*/
	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		// TODO Auto-generated method stub
		if(newConfig.orientation==Configuration.ORIENTATION_PORTRAIT)
		{   
			// TODO When the screen is PORTRAIT
			portraint = 1;
			setContentView(R.layout.book_page);
		}

		if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE)
		{
			// TODO When the screen is LANDSCAPE
			portraint = 2;
			setContentView(R.layout.book_page_horizontal);
		}
		findview();
		addListener();
		tvBookNameContent.setText(book.bookname);
		if(FileBo.BOOKTYPE_TXT.equals(book.booktype)){
			bookMark(BooksEngine.markPoint);
			Log.i("zkli","markPoint"+BooksEngine.markPoint);
		}else if(FileBo.BOOKTYPE_PDB.equals(book.booktype)){		
			bookMark(BooksEnginePDB.markPoint);
		}else if(FileBo.BOOKTYPE_CHM.equals(book.booktype)){
			
		}else if(FileBo.BOOKTYPE_HTML.equals(book.booktype)){
			
		}else if(FileBo.BOOKTYPE_PDF.equals(book.booktype)){
		
		}
		
		super.onConfigurationChanged(newConfig);
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(keyCode == KeyEvent.KEYCODE_BACK){
			this.finish();
		}
		return super.onKeyDown(keyCode, event);
	}
	
	@Override
	public void finish() {
		// TODO Auto-generated method stub
		if(BooksEnginePDB.str!=null){
			BooksEnginePDB.str = null;
		}
		BooksBo bo = new BooksBo(this, false);
		bo.addCurIndex(book.id, BooksEngine.markPoint);
		SharedPreferences sp = getSharedPreferences("lightNess", Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		editor.putFloat("ness", ness);
		editor.commit();
		System.gc();
		super.finish();
	}
	
	private void findview() {
		bookpagebg = (LinearLayout) findViewById(R.id.bookpagebg);
		btnBookStore = (Button) findViewById(R.id.btnBookStore);
		btnCatalogue = (Button) findViewById(R.id.btnCatalogue);
		btnLight = (Button) findViewById(R.id.btnLight);
		btnFont = (Button) findViewById(R.id.btnFont);
		btnSearch = (Button) findViewById(R.id.btnSearch);
		btnBookMark = (Button) findViewById(R.id.btnBookMark);
		tvBookNameContent = (TextView) findViewById(R.id.tvBookNameContent); 
		llyContentMain = (LinearLayout) findViewById(R.id.llyContentMain);
		tvMainContent = (TextView) findViewById(R.id.tvMainContent);
		sbrMainContent = (SeekBar) findViewById(R.id.sbrMainContent);
		llyCatelogTitle = (LinearLayout) findViewById(R.id.llyCatelogTitle);
//		btnContentCatelog = (Button) findViewById(R.id.btnContentCatelog);
//		btnContentMark = (Button) findViewById(R.id.btnContentMark);
//		lvCatalog = (ListView) findViewById(R.id.lvCatalog);
		btnLightEnter = (LinearLayout) findViewById(R.id.btnLightEnter);
		btnFontEnter = (LinearLayout) findViewById(R.id.btnFontEnter);
		btnFontEnterButtona1 = (Button) findViewById(R.id.btnFontEnterButtona);
		btnFontEnterButtonA2 = (Button) findViewById(R.id.btnFontEnterButtonA);
		btnFontEnterColorBlack = (Button) findViewById(R.id.btnFontEnterColorBlack);
		btnFontEnterColorBrown = (Button) findViewById(R.id.btnFontEnterColorBrown);
		btnLightBar = (SeekBar) findViewById(R.id.btnLightBar);
		if (portraint == 1) {
			tvMainContent = (TextView) findViewById(R.id.tvMainContent);
		} else if (portraint == 2) {
			tvMainContentLeft = (TextView) findViewById(R.id.tvMainContentLeft);
			tvMainContentRight = (TextView) findViewById(R.id.tvMainContentRight);
		}
	}

	private void addListener() {
		BtnBookStoreClick btnBookStoreClick = new BtnBookStoreClick(this);
		btnBookStore.setOnClickListener(btnBookStoreClick);
		BookpagebgClick bookpagebgClick = new BookpagebgClick(this,btnLightEnter,
				btnFontEnter);
		bookpagebg.setOnClickListener(bookpagebgClick);
		
		BtnCatalogueClick btnCatalogueClick = new BtnCatalogueClick(this,id,true);
		btnCatalogue.setOnClickListener(btnCatalogueClick);
		
		BtnLightClick btnLightClick = new BtnLightClick(this, btnLightEnter,
				btnFontEnter, showLightEnter);
		btnLight.setOnClickListener(btnLightClick);
		
		BtnFontClick btnFontClick = new BtnFontClick(this,btnLightEnter,
				btnFontEnter);
		btnFont.setOnClickListener(btnFontClick);
		
		BtnFontEnterButtonClick btnFontEnterButtonClick = new BtnFontEnterButtonClick(this,
				tvMainContent, tvMainContentLeft, tvMainContentRight,
				btnFontEnterButtonA2, btnFontEnterColorBlack,
				btnFontEnterColorBrown);
		btnFontEnterButtona1.setOnClickListener(btnFontEnterButtonClick);
		
		BtnFontEnterButtonAClick btnFontEnterButtonA2Click = new BtnFontEnterButtonAClick(
				this,tvMainContent, tvMainContentLeft, tvMainContentRight,
				btnFontEnterButtona1, btnFontEnterButtonA2,
				btnFontEnterColorBlack, btnFontEnterColorBrown);
		btnFontEnterButtonA2.setOnClickListener(btnFontEnterButtonA2Click);
		
		BtnColorBlackClick btnColorBlackClick = new BtnColorBlackClick(this,
				bookpagebg, btnFontEnterButtona1, btnFontEnterButtonA2,
				btnFontEnterColorBrown);
		btnFontEnterColorBlack.setOnClickListener(btnColorBlackClick);
		
		BtnColorBrownClick btnColorBrownClick = new BtnColorBrownClick(this,
				bookpagebg, btnFontEnterButtona1, btnFontEnterButtonA2,
				btnFontEnterColorBlack);
		btnFontEnterColorBrown.setOnClickListener(btnColorBrownClick);
		
		btnLightBar.setOnSeekBarChangeListener(btnLightBarClick);
		
		btnBookMark.setOnClickListener(new BtnBookMarkOnClickListener(this));
		if(portraint ==1){
			tvMainContent.setOnTouchListener(new MainContentOnTouchListener(this));
		}else if (portraint ==2){
			tvMainContentLeft.setOnTouchListener(new MainContentOnTouchListener(this));
			tvMainContentRight.setOnTouchListener(new MainContentOnTouchListener(this));
		}
		sbrMainContent.setOnSeekBarChangeListener(new SbrMainContentOnChangeListener(this));
		
		//btnSearch.setOnClickListener();
	}

	private void doing(int flag) {
		dg = new Dialog(this);
		dg.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dg.setContentView(R.layout.dia_loading);
		dg.show();
		SharedPreferences sp = getSharedPreferences("lightNess", Activity.MODE_PRIVATE);
		ness = sp.getFloat("ness", 100);
		brightnessMax(ness);
		showing();

	}

	/**从书签中返回结果调用*/
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		System.out.println("requestCode========>"+requestCode);
		System.out.println("resultCode========>"+resultCode);
		if(resultCode>=0){
			bookMark(resultCode);
		}else if (resultCode == -1){
			this.finish();
		}

	}
	
	private void showing() {
		tvBookNameContent.setText(book.bookname);
		String str = null;
		if(FileBo.BOOKTYPE_TXT.equals(book.booktype)){
			if (portraint == 1) {
				int fontSize = (int) tvMainContent.getTextSize();
				TextSizeUtil.fontSize = fontSize;
				BooksEngine.curLine = 0;
				lineCount  = TextSizeUtil.getLineCount(TextSizeUtil.fontSize, portraint);
				
				System.out.println("------------------lineCount"+lineCount);
				cu = new ContentUtil(this,book.bookpath,"宋体",StringConfig.VWIDE,"GBK",(short)1,portraint);
				if ( book.curIndex > 0 ){
					bookMark(book.curIndex);
				}else{
					cuf = new ContentUtilFirst(this, book.bookpath, "宋体",  StringConfig.VWIDE,
							"GBK", (short)1,portraint,cu.engine);
					cuf.engine.fileFirstStart = true;
					lineIndex = 0;
					//lineCount = TextSizeUtil.getLineCount(TextSizeUtil.fontSize, 1);
					//lineCount = TextSizeUtil.getLineCount((int)tvMainContent.getTextSize(), portraint);
					
					//TextSizeUtil.getLineCount(TextSizeUtil.fontSize, 1);
					System.out.println("lineCount"+TextSizeUtil.getLineCount(TextSizeUtil.fontSize, 1));
					cuf.setLine(lineIndex, lineCount);
					cuf.what = 1;
					new Thread(cuf).start();
					
					cd = new ContentDisp(this, book.bookpath, "宋体",StringConfig.VWIDE,
							"GBK", portraint,cu.engine,portraint);
					cd.setLine(lineIndex, lineCount);
					cd.what = portraint;
					Thread th= new Thread(cd);
					th.start();
					
				}
				
				cur = new ContentUtilReturn(this, book.bookpath, "宋体",
						StringConfig.VWIDE, "GBK", portraint, cu.engine);
				cc = new CursorController(cu.engine, cu, cd, cur, this, cuf);
			} else if (portraint == 2) {
				int fontSize = (int) tvMainContentLeft.getTextSize();
				TextSizeUtil.fontSize = fontSize;
				BooksEngine.curLine = 0;
				lineCount  = TextSizeUtil.getLineCount(TextSizeUtil.fontSize, portraint);
				
				cu = new ContentUtil(this,book.bookpath,"宋体",StringConfig.HWIDE,"GBK",(short)1,portraint);
				if ( book.curIndex > 0 ){
					bookMark(book.curIndex);
				}else{
					cuf = new ContentUtilFirst(this, book.bookpath, "宋体",  StringConfig.HWIDE,
							"GBK", (short)1,portraint,cu.engine);
					cuf.engine.fileFirstStart = true;
					lineIndex = 0;
					//lineCount = TextSizeUtil.getLineCount(TextSizeUtil.fontSize, 1);
					//lineCount = TextSizeUtil.getLineCount((int)tvMainContent.getTextSize(), portraint);
					
					//TextSizeUtil.getLineCount(TextSizeUtil.fontSize, 1);
					System.out.println("lineCount"+TextSizeUtil.getLineCount(TextSizeUtil.fontSize, 1));
					cuf.setLine(lineIndex, lineCount);
					cuf.what = 2;
					new Thread(cuf).start();
					
					cd = new ContentDisp(this, book.bookpath, "宋体",StringConfig.HWIDE,
							"GBK", portraint,cu.engine, portraint);
					cd.setLine(lineIndex, lineCount);
					cd.what = portraint;
					Thread th= new Thread(cd);
					th.start();
				}
				cur = new ContentUtilReturn(this, book.bookpath, "宋体",
						StringConfig.HWIDE, "GBK", portraint, cu.engine);
				cc = new CursorController(cu.engine, cu, cd, cur, this, cuf);
			}
			BookMarkBo.isMark(this);
			if(mark!=null){
				btnBookMark.setBackgroundResource(R.drawable.content_btn_onmark);
			}else{
				btnBookMark.setBackgroundResource(R.drawable.content_btn_outmark);
			}
		}else if(FileBo.BOOKTYPE_PDB.equals(book.booktype)){
			if (portraint == 1) {
				int fontSize = (int) tvMainContent.getTextSize();
				TextSizeUtil.fontSize = fontSize;
				BooksEnginePDB.curLine = 0;
				lineCount  = TextSizeUtil.getLineCount(TextSizeUtil.fontSize, portraint);
				
				cuPDB = new ContentUtilPDB(this,book.bookpath,"宋体",StringConfig.VWIDE,"GBK",(short)1,portraint);
				if ( book.curIndex > 0 ){
					bookMark(book.curIndex);
				}else{
					cufPDB = new ContentUtilFirstPDB(this, book.bookpath, "宋体",  StringConfig.VWIDE,
							"GBK", (short)1,portraint,cuPDB.engine);
					cufPDB.engine.fileFirstStart = true;
					lineIndex = 0;
					//lineCount = TextSizeUtil.getLineCount(TextSizeUtil.fontSize, 1);
					//lineCount = TextSizeUtil.getLineCount((int)tvMainContent.getTextSize(), portraint);
					
					//TextSizeUtil.getLineCount(TextSizeUtil.fontSize, 1);
					System.out.println("lineCount"+TextSizeUtil.getLineCount(TextSizeUtil.fontSize, 1));
					cufPDB.setLine(lineIndex, lineCount);
					cufPDB.what = 1;
					new Thread(cufPDB).start();
					
					cdPDB = new ContentDispPDB(this, book.bookpath, "宋体",StringConfig.VWIDE,
							"GBK", portraint,cuPDB.engine,portraint);
					cdPDB.setLine(lineIndex, lineCount);
					cdPDB.what = 4;
					Thread th= new Thread(cdPDB);
					th.start();
				}
				/*curPDB = new ContentUtilReturn(this, book.bookpath, "宋体",
						StringConfig.VWIDE, "GBK", portraint, cu.engine);*/
				cc = new CursorController(cuPDB.engine, cuPDB, cdPDB, this, cufPDB);
				
			} else if (portraint == 2) {
				int fontSize = (int) tvMainContentLeft.getTextSize();
				TextSizeUtil.fontSize = fontSize;
				BooksEnginePDB.curLine = 0;
				lineCount  = TextSizeUtil.getLineCount(TextSizeUtil.fontSize, portraint);
				
				cuPDB = new ContentUtilPDB(this,book.bookpath,"宋体",StringConfig.HWIDE,"GBK",(short)1,portraint);
				if ( book.curIndex > 0 ){
					bookMark(book.curIndex);
				}else{
					cufPDB = new ContentUtilFirstPDB(this, book.bookpath, "宋体",  StringConfig.HWIDE,
							"GBK", (short)1,portraint,cuPDB.engine);
					
					lineIndex = 0;
					//lineCount = TextSizeUtil.getLineCount(TextSizeUtil.fontSize, 1);
					//lineCount = TextSizeUtil.getLineCount((int)tvMainContent.getTextSize(), portraint);
					
					//TextSizeUtil.getLineCount(TextSizeUtil.fontSize, 1);
					System.out.println("lineCount"+TextSizeUtil.getLineCount(TextSizeUtil.fontSize, 1));
					cufPDB.setLine(lineIndex, lineCount);
					cufPDB.what = 7;
					new Thread(cufPDB).start();
					
					cdPDB = new ContentDispPDB(this, book.bookpath, "宋体",StringConfig.HWIDE,
							"GBK", portraint,cuPDB.engine, portraint);
					cdPDB.setLine(lineIndex, lineCount);
					cdPDB.what = 7;
					Thread th= new Thread(cdPDB);
					th.start();
				}
				curPDB = new ContentUtilReturnPDB(this, book.bookpath, "宋体",
						StringConfig.HWIDE, "GBK", portraint, cuPDB.engine);
				cc = new CursorController(cuPDB.engine, cuPDB, cdPDB, this, cufPDB);
				
			}
			BookMarkBo.isMark(this);
			if(mark!=null){
				btnBookMark.setBackgroundResource(R.drawable.content_btn_onmark);
			}else{
				btnBookMark.setBackgroundResource(R.drawable.content_btn_outmark);
			}
		}else if(FileBo.BOOKTYPE_CHM.equals(book.booktype)){
			
		}else if(FileBo.BOOKTYPE_HTML.equals(book.booktype)){
			
		}else if(FileBo.BOOKTYPE_PDF.equals(book.booktype)){
			
		}
	}

	/**控制本ACTIVITY的VIEW的HANDLER*/
	public Handler bcHandler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			switch (msg.what) {
			case 1:
				if( portraint==1 ){
					tvMainContent.setText(BooksEngine.content);
				}
				if(dg!=null){
					dg.cancel();
				}
				
				break;
			case 2:
				if(portraint == 2) {
					String str = BooksEngine.content;
					int midNo = 0 ;
					for(int i = 0 ;i< lineCount/2 ;i ++){
						midNo = str.indexOf('\n', midNo);
						midNo++;
					}
					String str1 = str.substring(0,midNo);
					String str2 = str.substring(midNo+1);
					tvMainContentLeft.setText(str1);
					tvMainContentRight.setText(str2);
				}
				if(dg!=null){
					dg.cancel();
				}
				break;
			case 3 :
				sbrMainContent.setVisibility(View.VISIBLE);
				break;
			case 4 :
				if( portraint==1 ){
					tvMainContent.setText(BooksEnginePDB.content);
				}
				break;
			case 5 :
				if(dg!=null){
					dg.cancel();
				}
				break;
			case 6 :
				if(dg!=null){
					dg.show();
				}
				break;
			case 7:
				if(portraint == 2) {
				String str = BooksEnginePDB.content;
				int midNo = 0 ;
				for(int i = 0 ;i< lineCount/2 ;i ++){
					midNo = str.indexOf('\n', midNo);
					midNo++;
				}
				String str1 = str.substring(0,midNo);
				String str2 = str.substring(midNo+1);
				tvMainContentLeft.setText(str1);
				tvMainContentRight.setText(str2);
				}
				if(dg!=null){
					dg.cancel();
				}
				break;
			default:
				break;
			}
			super.handleMessage(msg);
		}
	};
	
	
	@Override
	public boolean onTrackballEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		return false;
	}
	
	/**亮度调节的端口*/
	private OnSeekBarChangeListener btnLightBarClick = new SeekBar.OnSeekBarChangeListener() {

		public void onStopTrackingTouch(SeekBar seekBar) {
			// TODO Auto-generated method stub
			ness=seekBar.getProgress();
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
			// TODO Auto-generated method stub
			seekBar.setProgress((int)ness);
		}

		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			// TODO Auto-generated method stub
			
			float a = (float) progress / (float) 255;
			if (a <= 0.2f) {
				a = 0.2f;
			}
			brightnessMax(a);

		}
	};

	//显示亮度
	private void brightnessMax(float ness) {
		WindowManager.LayoutParams lp = getWindow().getAttributes();
		lp.screenBrightness = ness;
		getWindow().setAttributes(lp);
	}
	
	/**从字符索引取得内容*/
	public void bookMark(int markPoint){
		ContentUtilBookMark cubm = null;
		ContentUtilBookMarkPDB cubmPDB = null;
		
		if(FileBo.BOOKTYPE_TXT.equals(book.booktype)){
		
				if (this.portraint == 1) {
					cubm = new ContentUtilBookMark(this, book.bookpath, "宋体",
							StringConfig.VWIDE, "GBK", markPoint);
				} else if (this.portraint == 2) {
					cubm = new ContentUtilBookMark(this, this.book.bookpath, "宋体",
							StringConfig.HWIDE, "GBK", markPoint);
				}
				Thread th = new Thread(cubm);
				th.start();
				if (this.portraint == 1) {
					cd = new ContentDisp(this, this.book.bookpath, "宋体",
							StringConfig.VWIDE, "GBK", this.portraint, cubm.engine, portraint);
					cd.what = 1;
				} else if (this.portraint == 2) {
					cd = new ContentDisp(this, this.book.bookpath, "宋体",
							StringConfig.HWIDE, "GBK", this.portraint, cubm.engine, portraint);
					System.out.println("===portraint==2=====");
					cd.what = 2;
				}
				cd.setLine(0, lineCount);
				
				
				Thread ths= new Thread(cd);
				ths.start();
		}else if(FileBo.BOOKTYPE_PDB.equals(book.booktype)){	
			if (this.portraint == 1) {
				cubmPDB = new ContentUtilBookMarkPDB(this, book.bookpath, "宋体",
						StringConfig.VWIDE, "GBK", markPoint);
			} else if (this.portraint == 2) {
				cubmPDB = new ContentUtilBookMarkPDB(this, this.book.bookpath, "宋体",
						StringConfig.HWIDE, "GBK", markPoint);
			}
			Thread th = new Thread(cubmPDB);
			th.start();
			if (this.portraint == 1) {
				cdPDB = new ContentDispPDB(this, this.book.bookpath, "宋体",
						StringConfig.VWIDE, "GBK", this.portraint, cubmPDB.engine, portraint);
				cdPDB.what = 4;
			} else if (this.portraint == 2) {
				cdPDB = new ContentDispPDB(this, this.book.bookpath, "宋体",
						StringConfig.HWIDE, "GBK", this.portraint, cubmPDB.engine, portraint);
				System.out.println("===portraint==2=====");
				cdPDB.what = 7;
			}
			cdPDB.setLine(0, lineCount);
			
			
			Thread ths= new Thread(cdPDB);
			ths.start();
		}else if(FileBo.BOOKTYPE_CHM.equals(book.booktype)){
			
		}else if(FileBo.BOOKTYPE_HTML.equals(book.booktype)){
			
		}else if(FileBo.BOOKTYPE_PDF.equals(book.booktype)){
			
		}
	}
	
	public void hiddenOpenWins(){
		//btnLightEnter;
		//btnFontEnter;
		if(btnLightEnter.getVisibility()!=View.GONE){
			btnLightEnter.setVisibility(View.GONE);
		}
		showLightEnter=1;
		if(btnFontEnter.getVisibility()!=View.GONE){
			btnFontEnter.setVisibility(View.GONE);
		}
		showFontEnter = 1 ;
	}
	
	public void lastPageShowing(){
		Log.i("zkli", "lastpage");
		/*AlertDialog ad = new AlertDialog.Builder(this)
			.setTitle("已经是最后一页").create();
		ad.show();*/
		Toast.makeText(this, "已到达文件最后一页", Toast.LENGTH_SHORT).show();
		sbrMainContent.setProgress(100);
	}
}
